import { loginRequest } from './index'

export function getLoginCode() {
	return new Promise((resolve, reject) => {
		wx.login({
			timeout: 1000,
			success: res => {
				resolve(res)
			},
			fail: err => {
				reject(err)
			}
		})
	})
}

export function getLoginToken(code) {
	return loginRequest.post('/login', { code })
}

export function checkToken(token) {
	return loginRequest.post('/auth', {}, { token })
}

export function checkSession() {
	return new Promise((resolve, reject) => {
		wx.checkSession({
			success: () => {
				resolve(true)
			},
			fail: () => {
				reject(false)
			}
		})
	})
}
